using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Infrastructure
{
    /// <summary>
    /// 获取路径的辅助类
    /// </summary>
    public static class PathHelper
    {
        /// <summary>
        /// 获取当前目录
        /// </summary>
        /// <returns>当前目录</returns>
        public static string GetCurrentDirectory()
        {
            return Directory.GetCurrentDirectory();
        }

        /// <summary>
        /// 获取应用程序根目录
        /// </summary>
        /// <returns>应用程序根目录</returns>
        public static string GetBaseDirectory()
        {
            return AppContext.BaseDirectory;
        }

        /// <summary>
        /// 将相对路径转换为绝对路径,绝对路径则不转换。
        /// </summary>
        /// <param name="path">需要转换的路径</param>
        /// <returns>转换后的绝对路径</returns>
        public static string RelativeToAbsolute(string path)
        {
            // 判断绝对路径
            // Linux绝对路径以/开头,如/opt/file
            // Windows绝对路径包含:,如c:\file
            if (path.StartsWith("/") || path.Contains(":"))
                return path;

            return System.IO.Path.Combine(GetBaseDirectory(), path);
        }

    }
}
